#!/usr/bin/Rscript

args <- commandArgs(trailingOnly = TRUE); 
# Arguments: args[1]: path to mF data. args[2]: path to R scripts folder
print(args)


# Read the raw data, rownames and class names
setwd(args[1]);
arrayData = read.table(args[2],sep='\t');
rowNames = read.table(args[3],sep='\t', colClasses="character");
rowClasses= read.table(args[4]);
print(dim(rowNames));
print(dim(rowClasses));


# Assign the values for the rfsize:final size for random forest
# ntree2try: number of trees 2 try when tuning the random forest and mtry variables
# niter: number of iterations for tunning
rfsize= as.integer(args[6]);
ntree2try= as.integer(args[7]);
niter= as.integer(args[8]);


# Assign the folder with the R code, and the results folder to output results.
Rfolder=args[5]
resultsFolder=args[1]


#### maniputaling the data before to pass the run random fores analysis. 
## This is particular to mF from BFRM output.
d = dim(arrayData)
arrayData = arrayData[2:d[1],1:(d[2]-1)]
arrayData = t(arrayData)
r = dim(rowNames)
rowNames=rowNames[1,2:r[2]]
 

#print(arrayData)
########## Run random Forest Analysis

setwd(Rfolder)
source("runRandForestAnalysis.R")
results <- runrandForAnalysis(arrayData,rfsize,ntree2try, rowNames, rowClasses, niter, Rfolder,resultsFolder)

print(results)


